/*
 * Copyright (c) 2025 Li Auto Inc. and its affiliates
 * Licensed under the Apache License, Version 2.0(the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef OS_SYSCALL_INTERNAL_H
#define OS_SYSCALL_INTERNAL_H

#ifdef __cplusplus
extern "C" {
#endif

/* Including File */
#include <nuttx/config.h>
#include "Os_Types.h"
#include "os_syscall_types.h"

/* Global Enumeration Definition */
typedef enum {
	OS_SYSCALLID_ACTIVATETASK,
	OS_SYSCALLID_ACTIVATETASKASYNC,
	OS_SYSCALLID_SET_USER_TO_PRIVILEGE,
	OS_SYSCALLID_SETEVENT,
	OS_SYSCALLID_SETEVENTASYN,
	OS_SYSCALLID_CLEAREVENT,
	OS_SYSCALLID_WAITEVENT,
	OS_SYSCALLID_GETEVENT,
	OS_SYSCALLID_DISABLEALLINTERRUPTS,
	OS_SYSCALLID_ENABLEALLINTERRUPTS,
	OS_SYSCALLID_SUSPENDALLINTERRUPTS,
	OS_SYSCALLID_RESUMEALLINTERRUPTS,
	OS_SYSCALLID_SUSPENDOSINTERRUPTS,
	OS_SYSCALLID_RESUMEOSINTERRUPTS,
#if defined(CONFIG_RT_FRAMEWORK_SCHTBL) && (CONFIG_RT_FRAMEWORK_SCHTBL == 1)
	OS_SYSCALLID_STARTSCHEDULETABLEREL,
	OS_SYSCALLID_STARTSCHEDULETABLEABS,
	OS_SYSCALLID_STOPSCHEDULETABLE,
	OS_SYSCALLID_SETSCHEDULETABLEAPPID,
	OS_SYSCALLID_GETSCHEDULETABLESTATUS,
	OS_SYSCALLID_NEXTSCHEDULETABLE,
	OS_SYSCALLID_NEXTSCHEDULETABLEFROMSTOP,
	OS_SYSCALLID_STARTSCHEDULETABLESYNCHRON,
	OS_SYSCALLID_SYNCSCHEDULETABLE,
	OS_SYSCALLID_SETSCHEDULETABLEASYNC,
#endif
#if defined(CONFIG_RT_FRAMEWORK_SPINLOCK) && (CONFIG_RT_FRAMEWORK_SPINLOCK == 1)
	OS_SYSCALLID_GETSPINLOCK,
	OS_SYSCALLID_RELEASESPINLOCK,
	OS_SYSCALLID_TRYTOGETSPINLOCK,
	OS_SYSCALLID_GETSPINLOCKREAD,
	OS_SYSCALLID_GETSPINLOCKWRITE,
	OS_SYSCALLID_RELEASESPINLOCKREAD,
	OS_SYSCALLID_RELEASESPINLOCKWRITE,
	OS_SYSCALLID_TRYTOGETSPINLOCKREAD,
	OS_SYSCALLID_TRYTOGETSPINLOCKWRITE,
#endif
	OS_SYSCALLID_COUNT
} os_syscall_t;

typedef enum {
	OS_SYSCALLPARAMINDEX_1 = 0,
	OS_SYSCALLPARAMINDEX_2,
	OS_SYSCALLPARAMINDEX_3,
	OS_SYSCALLPARAMINDEX_4,
	OS_SYSCALLPARAMINDEX_5,
	OS_SYSCALLPARAMINDEX_COUNT
} os_syscall_param_index_t;

/* Global Type & Structure Definition */
typedef union {
	TaskType param_task_t;
	TickType param_tick_t;
	EventMaskType param_event_mask;
	EventMaskRefType param_event_mask_ref;
#if defined(CONFIG_RT_FRAMEWORK_SCHTBL) && (CONFIG_RT_FRAMEWORK_SCHTBL == 1)
	ScheduleTableType param_scheduletable;
	ScheduleTableStatusType param_scheduletable_status;
	ScheduleTableStatusRefType param_scheduletable_status_ref;
#endif
#if defined(CONFIG_RT_FRAMEWORK_SPINLOCK) && (CONFIG_RT_FRAMEWORK_SPINLOCK == 1)
	SpinlockIdType param_spinlock;
	TryToGetSpinlockType *param_try_to_get_spinlock_ref;
#endif
	uint32 param_uint32_t;
} os_syscall_param_t;

typedef union {
	Os_StatusType return_os_status;
} os_syscall_return_t;

struct syscall_data_s {
	os_syscall_t syscall_id;
	os_syscall_return_t syscall_return_value;
	os_syscall_param_t syscall_param[OS_SYSCALLPARAMINDEX_COUNT];
};

#ifdef __cplusplus
}
#endif

#endif /* OS_SYSCALL_INTERNAL_H */
